package com.psmorandi.peschampweb.android;

import android.app.ProgressDialog;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

public abstract class BaseActivity extends FragmentActivity {

	private ProgressDialog mProgressDialog = null;

	public void showToastMessage(int _strResorceID) {
		showToastMessage(getResources().getString(_strResorceID));
	}

	public void showToastMessage(final String _message) {

		runOnUiThread(new Runnable() {

			@Override
			public void run() {
				Toast.makeText(BaseActivity.this, _message, Toast.LENGTH_LONG)
						.show();

			}
		});
	}

	public void showIndeterminateProgress(final String title,
			final String message, final boolean cancelable) {
		runOnUiThread(new Runnable() {

			@Override
			public void run() {
				if (mProgressDialog == null || !mProgressDialog.isShowing()) {
					mProgressDialog = ProgressDialog.show(BaseActivity.this,
							title, message, true, cancelable);
				}
			}
		});
	}

	public void closeProgress() {
		runOnUiThread(new Runnable() {

			@Override
			public void run() {
				if (mProgressDialog != null) {
					if (mProgressDialog.isShowing()) {
						mProgressDialog.dismiss();
					}

					mProgressDialog = null;
				}
			}
		});
	}

}
